using Newtonsoft.Json;

namespace WWB.DisqusSharp.Model.DisqusService
{
    public class DisqusServiceResultBase : IDisqusServiceResult
    {
        [JsonProperty("code")]
        public string Code { get; set;}
        [JsonProperty("succeeded")]
        public bool Succeeded { get; set;}

        #region Implementation of IDisqusServiceResult

        public virtual ServiceError Error
        {
            get
            {
                if (IsError)
                {
                    return new ServiceError(Code, ErrorMessage);   
                }
                return null;
            }
        }

        public virtual bool IsError
        {
            get { return !Succeeded; }
        }

        public virtual bool IsSuccessful
        {
            get { return Succeeded; }
        }

        public virtual string JsonPayload
        {
            get { return string.Empty; }
        }

        #endregion

        protected virtual string ErrorMessage { get { return "UNKNOWN ERROR!"; } }
    }
}